clear;
close all;
%% 添加casadi
addpath("E:\Coding\matlab\casadi-3.6.7-windows64-matlab2018b");
import casadi.*

%% 处理线路数据
root_path = "real_line\";
folder_name = "北京北-崇礼\";
file_type = ".xls";

% GradientFilePath = strcat(root_path, folder_name, "坡道文件输入-递增", file_type);
CurveFilePath = strcat(root_path, folder_name, "曲线文件输入-递增", file_type);
% SpeedLimitPath = strcat(root_path, folder_name, "限速文件输入-递增", file_type);
% GradientData = readmatrix(GradientFilePath);
% CurveData = readmatrix(CurveFilePath);
% SpeedLimitData = readmatrix(SpeedLimitPath);

GradientData = readmatrix("virtual_line\line_info.xlsx","Sheet","坡度2");
CurveData = readmatrix(CurveFilePath);
SpeedLimitData = readmatrix("virtual_line\line_info.xlsx","Sheet","限速3");

%处理成仅3列，且把 km->m
GradientData = [GradientData(:,1:2).*1000 GradientData(:,3)];
CurveData = [CurveData(:,1:2).*1000 CurveData(:,3)];
SpeedLimitData = [SpeedLimitData(:,1:2).*1000 SpeedLimitData(:,3)];

%曲线数据补充平直道
CurveData = fill_curvedata(CurveData);
%补充缺失的限速数据
SpeedLimitData = fill_speedlimit(SpeedLimitData,250);

%% 结构体1：线路参数
LineInfo.gradient = GradientData;
LineInfo.curve = CurveData;
LineInfo.speedlimit = SpeedLimitData;
LineInfo.init_height = 1000; %初始海拔

%% 结构体2：列车参数
TrainInfo.abc = [0.55 0.003622 0.00011]; %CRH380B
TrainInfo.mass = 425; %吨 CRH380B - AW1
TrainInfo.rf = 0.06; % rotate factor 回转质量系数
TrainInfo.eta_gear = 0.9; %齿轮箱输出和输入功率之比
TrainInfo.motor_num = 16;

%% 结构体3：求解参数
QsInfo.pos_start = 45.12334;   %起点 km
QsInfo.pos_end = 82.3335; %终点 km
QsInfo.v_start = 80;
QsInfo.v_end = 0;
QsInfo.set_time = 1850;
QsInfo.step_x = 5; %求解步长1
QsInfo.step_t = 5;
QsInfo.t_err = 10;
QsInfo.T_st = [25 25]; %起始温度

%%
% sta = speedplan_cruise2(LineInfo,TrainInfo,QsInfo);
sta = speedplan_cruise(LineInfo,TrainInfo,QsInfo);